﻿
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data;
using Utils;
using PanasonicWarranty.DAL;
namespace PanasonicWarranty.Business
{
    public partial class pa_WarrantyExtend
    {
    	#region public properties
		[Required(ErrorMessage="WarrantyExtendID Required")]
		public int WarrantyExtendID { get; set; }
		public int? WarrantyID { get; set; }
		public string WarrantyTypeCode { get; set; }
		public DateTime? ExtendDate { get; set; }
		#endregion

		#region constructor
		public pa_WarrantyExtend(){ }

		public pa_WarrantyExtend(IDataReader rd)
		{
			this.WarrantyExtendID = (int)rd["WarrantyExtendID"];
			this.WarrantyID = rd["WarrantyID"].Equals(DBNull.Value) ? (int?)null : (int)rd["WarrantyID"];
			this.WarrantyTypeCode = rd["WarrantyTypeCode"].ToString();
			this.ExtendDate = rd["ExtendDate"].Equals(DBNull.Value) ? (DateTime?)null : (DateTime)rd["ExtendDate"];
		}
		#endregion

		#region private method
        private bool Create()
        {
            return DBpa_WarrantyExtend.Create(WarrantyExtendID, WarrantyID, WarrantyTypeCode, ExtendDate);
        }

        private bool Update()
        {
            return DBpa_WarrantyExtend.Update(WarrantyExtendID, WarrantyID, WarrantyTypeCode, ExtendDate);
        }
		#endregion

		#region public method
		public bool Save()
		{
            if(WarrantyExtendID != 0)
            {
                return Update();
            }
            else
            {
                return Create();
            }
		}
		#endregion

		#region static method
        public static bool Delete(int WarrantyExtendID)
        {
            return DBpa_WarrantyExtend.Delete(WarrantyExtendID);
        }

        public static List<pa_WarrantyExtend> GetAll()
        {
            return ObjectClass.CreateList<pa_WarrantyExtend>(DBpa_WarrantyExtend.GetAll());
        }

        public static pa_WarrantyExtend GetByKey(int WarrantyExtendID)
        {
            return ObjectClass.CreateInstance<pa_WarrantyExtend>(DBpa_WarrantyExtend.GetByKey(WarrantyExtendID));
        }

        public static List<pa_WarrantyExtend> GetByForeignKeys(int? WarrantyID, string WarrantyTypeCode)
        {
            return ObjectClass.CreateList<pa_WarrantyExtend>(DBpa_WarrantyExtend.GetByForeignKeys(WarrantyID, WarrantyTypeCode));
        }

        public static List<pa_WarrantyExtend> GetByTop(string top, string where, string order)
        {
            return ObjectClass.CreateList<pa_WarrantyExtend>(DBpa_WarrantyExtend.GetByTop(top, where, order));
        }
		#endregion
	}
}
